﻿<!DOCTYPE >
<html>
<head>
    <title>微街秀 > 推广设置</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
      <link href="plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link href="css/Makeset.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div>
        <div class="wamtop">
            <div class="topleft" onclick="javascript:history.back(-1);">
                <img src="img/5.jpg" />
            </div>
            <div class="topcententxt">
                推广设置</div>
        </div>
        <div style="width: 100%; background-color: white; border-bottom: 1px #D5D5D5 solid;">
            <div class="title">
            </div>
        </div>

        <div style="height: 100px; width: 100%; background: white; margin-top: 5px;" id="">
            <span style="line-height: 50px; margin-left: 20px; color: #404040;">地区</span>
            <select id="s_city" style="height: 30px; color: #8F8F8F; width: 90px; border: 0;
                background: #EDECEA; float: right; margin-top: 10px; margin-right: 20px; border-radius: 5px;">
            </select>
            <select id="s_province" style="height: 30px; color: #8F8F8F; width: 90px; border: 0;
                background: #EDECEA; float: right; margin-right: 20px; margin-top: 10px; border-radius: 5px;">
            </select>
            <br />
            <select id="s_county" style="height: 30px; color: #8F8F8F; width: 200px; border: 0;
                background: #EDECEA; float: right; margin-right: 20px; margin-top: 10px; border-radius: 5px;">
            </select>
        </div>


        <div style="height: 50px; margin-top: 5px; background: white; border-bottom: 1px #ccc solid;">
            <span style="line-height: 50px; margin-left: 20px; color: #404040;">分享数量</span>
            <input type="number" placeholder="大于100的数字" class="Number op_total" />
        </div>
        <div style="height: 50px; background: white; border-bottom: 1px #ccc solid;">
            <span style="line-height: 50px; margin-left: 20px; color: #404040;">分享价格</span>
            <input type="number" placeholder="最低人均1元起" class="pirce op_price" />
        </div>
        
        <div style="height: 100px; width: 100%; background: white; margin-top: 5px; display: none;">
            <span style="line-height: 50px; margin-left: 20px; color: #404040;">有效期</span>
            <div id="StartDate" class="SectDeta">
                <span id="StartYear"></span>年<span id="StartMoth"></span>月<span id="StartDay"></span>日
            </div>
            <br />
            <div id="EndDate" class="SectDeta">
                <span id="EndYear"></span>年<span id="EndMoth"></span>月<span id="EndDay"></span>日
            </div>
        </div>
        <div style="height: 50px; width: 100%; background: white; margin-top: 5px;">
            <span style="line-height: 50px; margin-left: 20px; color: #404040;">分享平台</span>
            <div id="Select2" style="height: 30px; width: 190px; border: 0; background: #EDECEA;
                float: right; margin-top: 10px; margin-right: 20px; border-radius: 5px; padding-left: 10px;
                line-height: 30px; color: #909090;">
                微信朋友圈
            </div>
        </div>
        <div style="height: 70px; margin-top:5px; padding:0px 20px 0px 20px; color:#909090;background: white; border-bottom: 1px #ccc solid;">
            说明：<br />
            全国1-5元，不同区域不同行业价格不一
        </div>
        <div style="height: 40px; width: 100%;">
            <div class="sumit" style="display: none;">
                保存</div>
            <div class="advrting shared" style="background: #ccc; display: none;">
                分享</div>
        </div>
        <div class="fixeddate">
            <div style="background: #F37B0B; height: 30px; line-height: 30px; text-align: center;
                color: white;">
                <span><span id="sYear"></span>- <span id="sMoth"></span>- <span id="sDay"></span>
                </span>
            </div>
            <div style="text-align: center;">
                <div style="width: 30%; float: left; margin: 0 0 10px 2.5%;">
                    <span style="line-height: 25px;">年</span>
                    <div class="bordercs">
                        <div id="Yearadd" class="Add" style="border-top-right-radius: 5px; border-top-left-radius: 5px;">
                            +</div>
                        <input type="text" class="datetxt" id="Year" />
                        <div id="YearCut" class="Add" style="border-bottom-right-radius: 5px; border-bottom-left-radius: 5px;">
                            -</div>
                    </div>
                </div>
                <div style="width: 30%; float: left; margin: 0 0 10px 2.5%;">
                    <span style="line-height: 25px;">月</span>
                    <div class="bordercs">
                        <div id="Mothadd" class="Add" style="border-top-right-radius: 5px; border-top-left-radius: 5px;">
                            +</div>
                        <input type="text" class="datetxt" id="Moth" />
                        <div id="MothCut" class="Add" style="border-bottom-right-radius: 5px; border-bottom-left-radius: 5px;">
                            -</div>
                    </div>
                </div>
                <div style="width: 30%; float: left; margin: 0 0 10px 2.5%;">
                    <span style="line-height: 25px;">日</span>
                    <div class="bordercs">
                        <div id="Dayadd" class="Add" style="border-top-right-radius: 5px; border-top-left-radius: 5px;">
                            +</div>
                        <input type="text" class="datetxt" id="Day" />
                        <div id="DayCut" class="Add" style="border-bottom-right-radius: 5px; border-bottom-left-radius: 5px;">
                            -</div>
                    </div>
                </div>
            </div>
            <div class="comfirn">
                确定
            </div>
            <div class="Cancel">
                取消
            </div>
        </div>
        <div class="fixedHiden">
        </div>
    </div>

    <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 0; right: -15%;">
            <img src="img/buzhou/3_5.png" class=" center-block" style="width: 60%;" />
            <div class=" text-center" style="">
                <p>
                    点击确认文章</p>
                <p>
                    自动跳转到</p>
                <p>
                    推广设置</p>
                <p>
               
                <p>
                    <button class=" btn btn-color btn-default " onclick="NextBZ(1)">
                        下一步</button></p>
            </div>
        </div>
    </div>
    <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 15%;">
            <img src="img/buzhou/3_6.png" class=" center-block" />
            <div class=" text-center" style="margin: -62px 0 0 33px;">
                <p>
                    设置分享数量</p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="UpBZ(1)">
                        上一步</button></p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="NextBZ(2)">
                        下一步</button></p>
            </div>
        </div>
    </div>
    <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 25%;">
            <img src="img/buzhou/3_7.png" class=" center-block" />
            <div class=" text-center" style="margin: -62px 0 0 33px;">
                <p>
                    设置分享价格</p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="UpBZ(2)">
                        上一步</button></p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="NextBZ(3)">
                        下一步</button></p>
            </div>
        </div>
    </div>
    <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 30%;">
            <img src="img/buzhou/3_8.png" class=" center-block" />
            <div class=" text-center" style="margin: -62px 0 0 33px;">
                <p>
                    设置推广投放地区</p>
                <p>
                    默认是全国</p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="UpBZ(3)">
                        上一步</button></p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="NextBZ(4)">
                        下一步</button></p>
            </div>
        </div>
    </div>
    <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 57%; left: 7%;">
            <img src="img/buzhou/3_9.png" class=" pull-left" style="width: 50%" />
            <div class=" text-center" style="position: absolute; top: -78%; left: 0px; width: 134%;">
                <p>
                    点击保存跳转的已发推广</p>
                <p>
                    可进行支付和设置</p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="UpBZ(4)">
                        上一步</button></p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="NextBZ(5)">
                        下一步</button></p>
            </div>
        </div>
    </div>
    <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 33%; left: 6%;">
            <div class=" text-center">
                <p>
                    点击分享</p>
                <p>
                    跳转到提交订单页面</p>
                <p>
                       <button class=" btn btn-color btn-default " onclick="SetBZ(32)">
                        知道了</button></p>
            </div>
            <img src="img/buzhou/3_10.png" class=" center-block" style="width: 50%" />
        </div>
    </div>

    <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="js/ajax-data.js" type="text/javascript"></script>
    <script src="js/base.js" type="text/javascript"></script>
    <script src="js/dialog.js" type="text/javascript"></script>
    <script src="js/MakeSet.js" type="text/javascript"></script>
    <script src="js/china-address.js" type="text/javascript"></script>
    <script>
        ShowBZ(32); //显示引导

        var page = 1;
        $(document).ready(function () {
            load(page);
        });
        function load(page) {
            if (!islogin()) { window.location.href = 'login.html'; return; }
            var id = getQueryString("id");
            AjaxStart("ajax/fc_article.ashx?getsetting", "id=" + id, function (data) {
                console.log(data);
                loadhtml(data.item);
            });
        }

        var state = 0;
        function loadhtml(item) {
            var ititem = item["title"];
            $(".title").html(ititem);
            $(".op_total").val(item["op_total"]);
            $(".op_price").val(item["op_price"]);
            state = item["state"];


            var a1 = item["op_area1"]; 
            if (a1 == '北京' || a1 == '北京' || a1 == '上海' || a1 == '天津' || a1 == '重庆')
                loadCity(item["op_area1"], item["op_area3"], item["op_area3"]);
            else
                loadCity(item["op_area1"], item["op_area2"], item["op_area3"]);
            if (item["state"] != 1) {
                $(".sumit").css("display", "");
                $(".shared").css("display", "");
                $(".sumit").bind("click", submits);     //保存事件
                if (item["op_total"] != null && item["op_price"] != null) {
                    $(".shared").bind("click", SetShared);  //分享事件
                    $(".shared").css("background", "#F37B0B");
                }
            }
        }

        //加载用户区域
        function loadCity(area1, area2, area3) {
            var opHtml = "<option value='{name}'>{name}</option>";
            //循环遍历省
            $(chinaDress).each(function () {
                $("#s_province").append(opHtml.replace(/{name}/g, this.n));
            });

            //监听省份点击
            $('#s_province').on("change", function () {
                var curOption = $(this).children('option:selected');
                //获取当前点击的Index
                var i = $(curOption).prevAll().length;
                //记录省得序号
                $("#s_city").attr("pro_index", i);
                $("#s_city").empty();
                $("#s_county").empty();     
                //循环遍历市
                $(chinaDress[i].sub).each(function () {
                    $("#s_city").append(opHtml.replace(/{name}/g, this.n));
                });
            });

            //监听市点击
            $('#s_city').on("change", function () {
                //当前市所属的省index
                var proIndex = parseInt($("#s_city").attr("pro_index"));
                var curOption = $(this).children('option:selected');
                //获取当前点击的Index
                var i = $(curOption).prevAll().length;
                $("#s_county").empty();
                //遍历区
                $(chinaDress[proIndex].sub[i].sub).each(function () {
                    $("#s_county").append(opHtml.replace(/{name}/g, this.n));
                });
            });

            if (area1 != null) {
                document.getElementById("s_province").value = area1;
                $('#s_province').change();
            }
            if (area2 != null) {
                document.getElementById("s_city").value = area2;
                $('#s_city').change();
            }
            if (area3 != null)
                document.getElementById("s_county").value = area3;

        }
        var tag = 1;
        function submits() {
            var id = getQueryString("id");
            var op_total = $(".op_total").val();
            var op_price = $(".op_price").val();
            var sysDate = new Date();
            var op_starttime = sysDate.getFullYear() + "-" + (sysDate.getMonth() + 1) + "-" + sysDate.getDate();
            var op_endtime = (sysDate.getFullYear() + 5) + "-" + (sysDate.getMonth() + 1) + "-" + sysDate.getDate();
            var op_area1 = "", op_area2 = "", op_area3 = "";
            var op_plat = 0;
            if (op_total == "") {
                Alert("请填写分享数量");
                return;
            }
            if (op_total.indexOf(".") > -1 || isNaN(op_total)) {
                Alert("分享数量必需是整数");
                return;
            }
            if (parseInt(op_total) < 100) {
                Alert("分享数量不能小于100");
                return;
            }

            if ($("#s_province").val() != "省份")
                op_area1 = $("#s_province").val();

            if ($("#s_county").val() != "请选择")
                op_area3 += $("#s_county").val();

            if ($("#s_city").val() != "请选择") {
                var arr = new Array("北京", "上海", "天津", "重庆");
                op_area2 += $("#s_city").val();
                for (var i = 0; i < arr.length; i++) {
                    if (arr[i] == op_area1) {
                        op_area2 = op_area1;
                        op_area3 = $("#s_city").val();
                        break;
                    }
                }
            }

            if (op_price == "") {
                Alert("请填写分享价格");
                return;
            }
            op_area1 = op_area1.replace("请选择", "");
            op_area2 = op_area2.replace("请选择", "");
            op_area3 = op_area3.replace("请选择", "");

            
                if (isNaN(op_price) || parseFloat(op_price) < 1) {
                    Alert("分享单价不能小于1元");
                    return;
                }
            

            if (!TimeCheck(sysDate.getFullYear() + "-" + (sysDate.getMonth() + 1) + "-" + sysDate.getDate(), op_starttime)) {
                Alert('开始日期必需大于今天');
                return;
            }
            if (!TimeCheck(op_starttime, op_endtime)) {
                Alert('截止日期不能小于开始日期');
                return;
            }

            
            if (!islogin()) { window.location.href = 'login.html'; return; }
            var param = "id=" + id + "&op_price=" + op_price + "&op_total=" + op_total + "&op_area1=" + op_area1 + "&op_area2=" + op_area2 + "&op_area3=" + op_area3 + "&op_starttime=" + op_starttime + "&op_endtime=" + op_endtime + "&op_plat=" + op_plat;
            AjaxStart("ajax/fc_article.ashx?setting", param, function (data) {
                if (data.code != 0)
                    Alert(data.msg);
                else {
                    if (tag == 1) {
                        Alert("保存成功");
                        setTimeout(function () { window.location.href = "Makead_1.html"; }, 100);
                    }
                    else {
                        Alert("分享需要付费，请先支付");
                        setTimeout(function () { window.location.href = "makefx.html?id=" + id }, 1000);
                    }
                }
                tag = 1;
            });
        }

        function TimeCheck(a, b) {
            var arr = a.split("-");
            var starttime = new Date(arr[0], arr[1], arr[2]);
            var starttimes = starttime.getTime();
            var arrs = b.split("-");
            var lktime = new Date(arrs[0], arrs[1], arrs[2]);
            var lktimes = lktime.getTime();
            if (starttimes > lktimes) {
                return false;
            }
            return true;
        }

        //设置分享状态
        function SetShared() {
            tag = 2;
            submits();
        }
    </script>
</body>
</html>
